﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.WowAddonStudio.Project.Import;
using Microsoft.WowAddonStudio.Project.Import.Folder;
using NUnit.Framework;

namespace WowProjectPackage.Tests.Import.Folder
{
    /// <summary>
    /// Implements test cases for folder import plugin.
    /// </summary>
    [TestFixture]
    public class FolderImportPluginTest : ImporterBaseTest
    {
        #region Private members
        private FolderImportPlugin importer;
        #endregion

        #region Initialization
        [SetUp]
        public override void SetUp()
        {
            base.SetUp();
            importer = new FolderImportPlugin();
        }

        [TearDown]
        public override void TearDown()
        {
            base.TearDown();
        }
        #endregion

        #region Test cases
        [Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void TestNullSettings()
        {
            importer.Import(null);
        }

        [Test]
        [ExpectedException(typeof(ArgumentException), ExpectedMessage = "Non-existing folder specified for import.", MatchType = MessageMatch.Contains)]
        public void TestNonExistingImportLocation()
        {
            importer.Import(new FolderImportSettings(nonExistingUri));
        }

        [Test]
        public void TestPlainDirectoryImport()
        {
            var result = importer.Import(new FolderImportSettings(plainUri)) as List<IAddonItem>;
            Assert.IsNotNull(result);
            Assert.AreEqual(result.Count, 3);
            Assert.AreEqual(result.Count(item => item.Type == FileType.Code), 1);
            Assert.AreEqual(result.Count(item => item.Type == FileType.Frame), 1);
            Assert.AreEqual(result.Count(item => item.Type == FileType.TableOfContents), 1);
        }

        [Test]
        public void TestRecursiveDirectoryImport()
        {
            var result = importer.Import(new FolderImportSettings(recursiveUri)) as List<IAddonItem>;
            Assert.IsNotNull(result);
            Assert.AreEqual(result.Count, 3);
            Assert.AreEqual(result.Count(item => item.Type == FileType.Code), 1);
            Assert.AreEqual(result.Count(item => item.Type == FileType.Frame), 1);
            Assert.AreEqual(result.Count(item => item.Type == FileType.TableOfContents), 1);
        }

        [Test]
        public void TestRealisticDirectoryImport()
        {
            var result = importer.Import(new FolderImportSettings(realisticUri)) as List<IAddonItem>;
            Assert.IsNotNull(result);
            Assert.AreEqual(result.Count, 11);
            Assert.AreEqual(result.Count(item => item.Type == FileType.Code), 1);
            Assert.AreEqual(result.Count(item => item.Type == FileType.Frame), 1);
            Assert.AreEqual(result.Count(item => item.Type == FileType.TableOfContents), 1);
            Assert.AreEqual(result.Count(item => item.Type == FileType.None), 8);
        }
        #endregion
    }
}